package com.neutech.neufin.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.neutech.neufin.mapper.ExpenseClassMapper;
import com.neutech.neufin.service.ExpenseClassService;
import com.neutech.neufin.vo.ViewData;
import com.neutech.po.ExpenseClass;

@Service
public class ExpenseClassServiceImpl implements ExpenseClassService{
	@Autowired
	private ExpenseClassMapper expenseClassMapper;
	@Override
	public List<ExpenseClass> queryAll() {
		// TODO Auto-generated method stub
		return expenseClassMapper.queryAll();
	}
	@Override
	public ExpenseClass findExpenseClassById(int id) {
		return expenseClassMapper.findExpenseClassById(id);
	}
	@Override
	public int addNewExpenseClass(ExpenseClass expenseClass) {
		// TODO Auto-generated method stub
		int num =  expenseClassMapper.addNewExpenseClass(expenseClass);
		return num;
	}
	@Override
	public ViewData getExps(Map<String,Object> map) {
		// TODO Auto-generated method stub
		//前端传递的pageNumber页码数，转换为数字，并且减一，绕后替换原有的map中的值；
		String pageNumber = (String)map.get("pageNumber");
		try{
			Integer pn = new Integer(pageNumber);
			pn = pn - 1;
			if(pn < 0){
				pn = 0;
			}
			pn =pn * 10;
			map.put("pageNumber", pn);
		}catch(Exception e){
			map.put("pageNumber", 0);
		}
		System.out.println(map.get("pageNumber"));
		System.out.println(map.get("ExpName"));
		ViewData vd = new ViewData();
		vd.setMap(expenseClassMapper.getExps(map));
		vd.setTotalNumber(expenseClassMapper.getExpsCount(map));
		return vd;
	}

}
